﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ForumLibrary.Data;
using System.Web.UI.HtmlControls;

public partial class Account : System.Web.UI.Page
{
    string friendRemoved;
    protected void Page_Load(object sender, EventArgs e)
    {
        HtmlGenericControl forum = (HtmlGenericControl)Page.Master.FindControl("Forum");
        forum.Attributes.Remove("class");

        HtmlGenericControl notifications = (HtmlGenericControl)Page.Master.FindControl("Notifications");
        forum.Attributes.Remove("class");

        HtmlGenericControl account = (HtmlGenericControl)Page.Master.FindControl("Account");
        account.Attributes.Add("class", "active");

        if (Session["username"] != null)
        {
            ForumManager manager = new ForumWebManager();
            ForumLibrary.Data.User user = (User)manager.getUser(Session["username"].ToString());
            SettingsFirstNameLabel.Text = user.FirstName;
            SettingsLastNameLabel.Text = user.LastName;
            SettingsPhoneNumberLabel.Text = user.PhoneNumber;
            SettingsEmailLabel.Text = user.Email;
        }
    }
    protected void SearchButton_Click(object sender, EventArgs e)
    {
        SearchDS.SelectParameters["searchedUser"] = new Parameter("searchedUser", TypeCode.String, SearchTextBox.Text);
        SearchDS.Select();
    }
    protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        string friendBeingAdded = GridView1.Rows[e.NewSelectedIndex].Cells[1].Text;
        FriendsDS.InsertParameters["friendAdding"] = new Parameter("friendAdding", TypeCode.String, Session["username"].ToString());
        FriendsDS.InsertParameters["friendAdded"] = new Parameter("friendAdded", TypeCode.String, friendBeingAdded);
        FriendsDS.Insert();
        SearchDS.SelectParameters["searchedUser"] = new Parameter("searchedUser", TypeCode.String, SearchTextBox.Text);
        SearchDS.Select();
    }

    protected void RemoveFriend_Click(object sender, EventArgs e)
    {
        friendRemoved = ((Button)sender).CommandArgument;
        FriendsDS.Delete();
    }
    protected void ListView1_ItemDeleting(object sender, ListViewDeleteEventArgs e)
    {
        
    }
    protected void  FriendsDS_Deleting(object sender, ObjectDataSourceMethodEventArgs e)
    {
        e.InputParameters["friendRemoving"] = Session["username"];
        e.InputParameters["friendRemoved"] = friendRemoved;
    }
}